<?php

require_once "Zend/Registry.php";
require_once "ZendX/JQuery/View/Helper/UiWidget.php";
class Application_JQuery_View_Helper_Ckeditor extends ZendX_JQuery_View_Helper_UiWidget
{

    private $_defaultToolbar = array(
                                        array('Format','Font','FontSize'),
                                        array('Bold','Italic','Underline','Strike','-','Subscript','Superscript'),
                                        array('Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker'),
                                        array('Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'),
                                        '/',
        array('NumberedList','BulletedList','-','Outdent','Indent','Blockquote'),
                                        array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
                                        array('Link','Unlink','Anchor'),
                                        array('Image','Table','HorizontalRule','Smiley','SpecialChar'),
                                        array('TextColor','BGColor'),
                                        array('Maximize', 'ShowBlocks','-','Templates','Source','-','About')
                                    );

    private $_defaultSkin = 'chris';

    public function ckeditor($id, $value = null, array $params = array(), array $attribs = array())
    {
        $attribs = $this->_prepareAttributes($id, $value, $attribs);

        if(!isset($params['toolbar']) or empty($params['toolbar'])) $params['toolbar'] = $this->_defaultToolbar;
        if(!isset($params['skin']) or empty($params['skin'])) $params['skin'] = $this->_defaultSkin;
        $params = ZendX_JQuery::encodeJson($params);
        $js = sprintf('%s("#%s").ckeditor(%s);',
                ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),
                $attribs['id'],
                $params
        );

        $this->jquery->addJavascriptFile('/js/ckeditor/ckeditor.js');
        $this->jquery->addJavascriptFile('/js/ckeditor/adapters/jquery.js');
        $this->jquery->addOnLoad($js);
        return $this->view->formTextarea($id, $value, $attribs);
    }

}
